﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace WebApplication1.App_Start
{
    public class ViewResult:IResult
    {
        private string viewName = null;
        public ViewResult(string viewName)
        {
            this.viewName = viewName;
        }
        public void Execute(HttpContext context, string controllerName, string actionName)
        {
            var path = Path.Combine(HttpRuntime.AppDomainAppPath, "View", controllerName.Replace("Controller",""), (string.IsNullOrEmpty(this.viewName) ? actionName : this.viewName) + ".html");
            using (var file = File.Open(path, FileMode.Open))
            {
                using (var reader = new StreamReader(file))
                {
                    context.Response.Write(reader.ReadToEnd());
                }
            }
        }
    }
}